package com.md.api.common.utils;

import java.util.UUID;

/**
 * @ClassName: IdGenerate
 * @Description: ID生成器
 * @author yzh
 * @date 2017年5月16日 上午9:00:03
 * 
 */
public class IdUtil {

	// 序列ID
	private static int sequenceId = 2147483640;
	// 数据中心ID
	private static final long dataCenterId = 1l;

	private static Object obj = new Object();

	/** 
	* @Title: nextId 
	* @Description: 获得唯一id 
	* @param ADataCenterId 数据中心ID
	* @return
	*/
	public static Long nextId(Long ADataCenterId) {
		synchronized (obj) {
			sequenceId = sequenceId + 1;
			Long tempDataCenterId = null == ADataCenterId ? dataCenterId : ADataCenterId;
			return (((long) (tempDataCenterId & 0xFFFF)) << 48)
					| (((System.currentTimeMillis() / 1000) & 0x00000000FFFFFFFFl) << 16)
					| (sequenceId & 0x0000FFFF);
		}
	}


	/**
	 * 生成uuid
	 * @return java.lang.String
	 **/
	public static String uuid(){
		return UUID.randomUUID().toString().replaceAll("-", "").toLowerCase();
	}
}
